package com.yztc.love_travel.ui.fourtrip;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.yztc.love_travel.R;
import com.yztc.love_travel.adater.fourtrip.FourTripAdapter;
import com.yztc.love_travel.bean.fourtrip.FourTripBean;
import com.yztc.love_travel.constant.URLConstant;
import com.yztc.love_travel.ui.fourtrip.presenter.IFourTripPresenter;
import com.yztc.love_travel.ui.fourtrip.presenter.FourTripPresenterImpl;
import com.yztc.love_travel.ui.fourtrip.view.IFourTripView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ReligionCultureActivity extends AppCompatActivity implements IFourTripView {

    @BindView(R.id.religion_culture_rv)
    RecyclerView recyclerView;

    private IFourTripPresenter mPresenter;
    private Context mContext;
    private List<FourTripBean.ListBean.DestinationListBean> mList; //数据源
    private FourTripAdapter adapter; //适配器

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_region_culture);
        ButterKnife.bind(this);

        mContext = this;
        initPresenter();
        loadData();
        initRecyclerView();

    }

    //初始化RecyclerView
    private void initRecyclerView() {
        mList = new ArrayList<>();
        adapter = new FourTripAdapter(mContext,mList);
        recyclerView.setAdapter(adapter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext, OrientationHelper.VERTICAL,false);
        recyclerView.setLayoutManager(layoutManager);
    }


    //加载数据
    private void loadData() {
        Map<String, Object> params = new HashMap<>();
        params.put(URLConstant.ReligionCulture.PAGENO, 0);
        params.put(URLConstant.ReligionCulture.PAGESIZE, 20);
        params.put(URLConstant.ReligionCulture.SPECIALSUBJECTED, 7);
        params.put(URLConstant.ReligionCulture.STATUS, 1);
        mPresenter.getFourTripBean(URLConstant.ReligionCulture.URL_REGION_BASE, params);
    }

    private void initPresenter() {
        mPresenter = new FourTripPresenterImpl(this,null);
    }

    @Override
    public void loadStart() {

    }

    @Override
    public void loadFinish() {

    }

    @Override
    public void loadError() {
        Toast.makeText(mContext, "加载数据失败", Toast.LENGTH_SHORT).show();
    }

    //显示加载完成的数据
    @Override
    public void showFourTripBeanData(FourTripBean fourTripBean) {
        List<FourTripBean.ListBean.DestinationListBean> destinationList = fourTripBean.getList().getDestinationList();
        mList.addAll(destinationList);
        adapter.notifyDataSetChanged();
    }
}
